Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

632
Vistas
Unaligned x scales for two Chartjs-chart types with the same configuration - only difference is "chart type" (bar/line)

I built a line chart & a bar chart in Chartjs with exactly the same configuration, but for some reason the x-scales of both charts are different as you can see in the picture below.

enter image description here

The configuration for the both charts is the same, the only difference is the chart type:

function getOptions() {
    return {
        animation: false,
        responsive: true,
        maintainAspectRatio: false,
        plugins: {
            tooltip: false,
            legend: {
                display: false
            },
            title: {
                display: false
            }
        },
        elements: {
            line: {
                fill: true
            },
            point: {
                radius: 0
            }
        },
        scales: {
            x: {
                type: "time",
                time: {
                    displayFormats: {
                        second: 'HH:mm:ss',
                        minute: 'HH:mm',
                        hour: 'HH'
                    },
                    unit: 'minute',
                    stepSize: 1,
                    min: '00:00:00',
                    max: '23:59:59',
                },
                grid: {
                    display: true,
                    drawBorder: true,
                    drawOnChartArea: true,
                    drawTicks: true,
                    color: function(context) {
                        return '#fff';
                    },
                }
            },
            y: {
                beginAtZero: true,
                grid: {
                    display: true,
                    drawBorder: false,
                    color: function(context) {
                        return '#fff';
                    },
                },
            }
        }
    };
}

I noticed that the x axes do align perfectly, if I set the "stepSize" to 'seconds'. This probably has to do with the fact that the data inserted into the chart is second-data.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This is because the bar chart sets the offset property on the x axis scale to true.

https://www.chartjs.org/docs/3.8.0/axes/cartesian/category.html#common-options-to-all-cartesian-axes

So to align them you either have to set it to false for the bar chart or to true for the line chart

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda